﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TuongLaiDangCho.DTO;
using System.Data.OleDb;

namespace TuongLaiDangCho.DAO
{
    class DieuMoiDAO
    {
        public static DataTable LoadNews(DieuMoiDTO news)
        {
            string sql = "Select * from DIEUMOI where NgayThang=#" + news.NgayThang.ToShortDateString() + "#";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            cn.Close();
            return dt;
        }

        public static void InsertNews(DieuMoiDTO news)
        {
            string sql = "Insert Into DIEUMOI(NgayThang, NoiDung, GhiChu) values(#" + news.NgayThang.ToShortDateString() + "#,'" + news.NoiDung+ "','"+news.GhiChu+"')";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void UpdateNews(DieuMoiDTO news)
        {
            string sql ="Update DIEUMOI set NoiDung='"+news.NoiDung+"' , GhiChu='"+news.GhiChu+"' where ID="+news.Id.ToString()+"";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void DeleteNews(DieuMoiDTO news)
        {
            string sql="Delete From DIEUMOI where ID="+news.Id.ToString()+"";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }
    }
}
